package com.fz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.entity.Repair;
import com.fz.service.RepairService;
import com.fz.service.UserService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 存储用户报修信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/repair")
public class RepairController {
    @Resource
    RepairService repairService;
    @Resource
    UserService tUserService;
    @GetMapping("/list")
    List<Repair> list(){
        List<Repair> repairList=repairService.list();

        return repairService.updateview(repairList);
    }

    @PostMapping("/add")
    ResultVo<Boolean> add(Integer userId, String type, String content, LocalDateTime repairTime){
        String username= tUserService.getUsernameById(Long.valueOf(userId));
        //return ResultVo.success(repairService.add(userId, type, content, repairTime,0),"添加维修申请成功");
        return ResultVo.success(repairService.add(userId, type, content, repairTime,0,username),"添加维修申请成功");

    }


    @GetMapping("/getById")
    ResultVo<Repair> getById(Long id)
    {
        return ResultVo.success(repairService.getById(id));
    }

    @GetMapping("/check")
    ResultVo<Boolean>check(Long id,String field,String value){
        return ResultVo.success(repairService.check(id,field,value));
    }

    @PostMapping("/update")
    ResultVo<Boolean> update(Long id, String type, String content, LocalDateTime repairTime){
        return ResultVo.success(repairService.update(id,type,content,repairTime),"修改维修表单成功");
    }
    @PostMapping("/pass")
    ResultVo<Boolean> pass(Long id,Integer status,Integer statu){
        return ResultVo.success(repairService.pass(id,status,statu),"维修通过成功！");
    }
    @PostMapping("/reject")
    ResultVo<Boolean> reject(Long id,Integer status,Integer statu){
        return ResultVo.success(repairService.reject(id,status,statu),statu==2?"驳回报修申请成功！":"报修状态重置成功，请尽快处理！");
    }


    @PostMapping("/del")
    ResultVo<Boolean>del(Long id,Integer status)
    {
        return ResultVo.success(repairService.del(id,status),"撤销维修表单成功");
    }

    @PostMapping("/llist")
    ResultVo<IPage<Repair>>llist(Long userId, Integer pageNo, Integer pageSize)
    {return ResultVo.success(repairService.getList(userId, pageNo, pageSize));}
    @PostMapping("/list2")
    ResultVo<IPage<Repair>> list2(Integer pageNo, Integer pageSize){
        return ResultVo.success(repairService.showList( pageNo, pageSize));
    }
    @PostMapping("/search")
    ResultVo<IPage<Repair>> search(String input,Integer pageNo, Integer pageSize){
        return ResultVo.success(repairService.search(input,pageNo,pageSize),"搜索成功！");
    }

}
